# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-fix
_pkgname=fix
pkgver=20220121
_commit=a288f05de716bcc9e82527f4cf440f9aebe965ae
pkgrel=2
pkgdesc="Algorithmic building blocks for memoization, recursion, and more"
url="https://gitlab.inria.fr/fpottier/fix"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.0-only"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="dune ocaml"
options="!check"    # tests take a long time to run
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://gitlab.inria.fr/fpottier/fix/-/archive/$pkgver/archive.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver-$_commit"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build -p fix @install --no-buffer --verbose
}

check() {
	dune runtest --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml

	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
a851d8783c0c519c6e55359a5c471af433058872409c29a1a7bdfd0076813341ad2c0ebd1ce9e28bff4d4c729dfbc808c41c084fe12a42b45a2b5e391e77ccd2  ocaml-fix-20220121.tar.gz
"
